import { delDepartmentReq, getDepartmentTreeReq } from '@/service/modules/department'
import { Department } from '@/service/modules/department/types'
import { reactive } from 'vue'

export function useDepartment() {
  const departmentVariables = reactive({
    departmentOptions: new Array<Department>()
  })
  const getDepartmentOptions = async () => {
    const res = await getDepartmentTreeReq()
    if (res.resp_code === 0) {
      const departments = res.data as Department[]
      departmentVariables.departmentOptions = departments
    }
  }

  const delDepartment = async (id: number) => {
    const res = await delDepartmentReq(id)
    if (res.resp_code === 0) {
      getDepartmentOptions()
    }
  }
  return { departmentVariables, getDepartmentOptions, delDepartment }
}
